package com.parking.order.consumer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.parking.common.core.model.RedisKey;
import com.parking.common.core.model.StateData;
import com.parking.common.web.util.RedisUtil;
import com.parking.order.client.dto.StallDto;
import com.parking.order.dao.*;
import com.parking.order.model.*;
import com.parking.order.model.param.AlipayRefundParam;
import com.parking.order.service.ICentifiedMoneyService;
import com.parking.order.service.IPlatformMoneyService;
import com.parking.order.service.IRentersMoneyService;
import com.parking.order.util.AlipayUtil;
import com.parking.order.util.BasicInfoUtil;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 出租人 物业 平台流水记录消费者
 * */
@Component
public class MoneyConsumer {
    /**
     * 平台流水数据层
     * */
    @Autowired
    private PlatformMoneyDao platformMoneyDao;
    /**
     * 平台流水服务层
     * */
    @Autowired
    private IPlatformMoneyService platformMoneyService;
    /**
     * 物业流水数据层
     * */
    @Autowired
    private CentifiedMoneyDao centifiedMoneyDao;
    /**
     * 物业流水服务层
     * */
    @Autowired
    private ICentifiedMoneyService certifiedMoneyService;
    /**
     * 出租客流水数据层
     * */
    @Autowired
    private RentersMoneyDao rentersMoneyDao;
    /**
     * 出租客流水服务层
     * */
    @Autowired
    private IRentersMoneyService rentersMoneyService;
    /**
     * 订单信息数据层
     * */
    @Autowired
    private OrderInfoDao orderInfoDao;
    /**
     * 超时订单数据层
     * */
    @Autowired
    private OrderOvertimeDao orderOvertimeDao;
    /**
     * 工具类 负责调用其他模块接口
     * */
    @Autowired
    private BasicInfoUtil basicInfoUtil;
    /**
     * 支付工具类
     * */
    @Autowired
    private AlipayUtil alipayUtil;

    /**
     * Redis工具类
     * */
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 用户下单后生成三方收入流水
     * 参数 orderInfoNum 订单编号
     * */
    @RabbitHandler
    @Transactional
    @RabbitListener(queuesToDeclare = {@Queue(value="moneyByAdd")})
    public void moneyByAddConsumer(String orderInfoNum) throws Exception {
        Integer moneyType = StateData.ORDER_MONEY_TYPE_ADD_ORDER;

        long poss = platformMoneyDao.selectCount(new QueryWrapper<PlatformMoney>().eq("order_info_num", orderInfoNum).eq("money_type",StateData.ORDER_MONEY_TYPE_ADD_ORDER));
        if(poss==0){
            System.out.println("===============普通订单支付 添加流水=========================");

            LocalDateTime now = LocalDateTime.now();
            OrderInfo order = orderInfoDao.selectOne(new QueryWrapper<OrderInfo>().eq("order_info_num",orderInfoNum));

            // 添加平台流水日志
            PlatformMoney platMoney = new PlatformMoney(now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());

            StallDto stall = basicInfoUtil.getStallInfo2(order.getStallInfoId());
            System.out.println("===============================获得车位和订单信息=================================");
            System.out.println("物业信息Id:"+stall.getCertifiedInfoId());
            System.out.println("出租客信息Id:"+stall.getRentersInfoId()+"(null表示非物业)");
            System.out.println("订单价格:"+order.getOrderPrice());

            if(stall.getRentersInfoId()==null){
                // 添加物业流水日志
                platMoney.setMoneyNum(order.getOrderPrice().multiply(StateData.ORDER_RATE_PLATFORM_FROM_CERTIFIED));
                CentifiedMoney certifiedMoney = new CentifiedMoney(stall.getCertifiedInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                certifiedMoney.setMoneyNum(order.getOrderPrice().multiply(StateData.ORDER_RATE_CERTIFIED));
                centifiedMoneyDao.insert(certifiedMoney);

                System.out.println("=======================获得分成信息=======================");
                System.out.println("物业平台 物业分成:"+StateData.ORDER_RATE_CERTIFIED);
                System.out.println("物业平台 平台分成:"+StateData.ORDER_RATE_PLATFORM_FROM_CERTIFIED);

                System.out.println("===============1 添加物业流水=========================");
                System.out.println("添加时间:"+certifiedMoney.getAddTime());
                System.out.println("流水类型:"+certifiedMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
                System.out.println("订单Id:"+certifiedMoney.getOrderInfoId());
                System.out.println("订单编号:"+certifiedMoney.getOrderInfoNum());
                System.out.println("流水金额:"+certifiedMoney.getMoneyNum());
                System.out.println("物业信息Id:"+certifiedMoney.getCertifiedInfoId());
                System.out.println("物业流水Id:"+certifiedMoney.getCertifiedMoneyId());

                // 更新物业收入统计
                System.out.println("===============2 统计物业收入与出租小时数=========================");
                addCertifiedIncome(certifiedMoney.getCertifiedInfoId(), certifiedMoney.getMoneyNum());
                addCertifiedStallHour(certifiedMoney.getCertifiedInfoId(), order.getEnduHour());
            }

            if(stall.getRentersInfoId()!=null){
                // 添加出租客流水日志
                platMoney.setMoneyNum(order.getOrderPrice().multiply(StateData.ORDER_RATE_PLATFORM_FROM_RENTERS));
                RentersMoney rentersMoney = new RentersMoney(stall.getRentersInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                rentersMoney.setMoneyNum(order.getOrderPrice().multiply(StateData.ORDER_RATE_RENTERS));
                rentersMoneyDao.insert(rentersMoney);

                System.out.println("=======================获得分成信息=======================");
                System.out.println("出租客平台 出租客分成:"+StateData.ORDER_RATE_RENTERS);
                System.out.println("出租客平台 平台分成:"+StateData.ORDER_RATE_PLATFORM_FROM_RENTERS);

                System.out.println("===============1 添加出租客流水=========================");
                System.out.println("流水类型:"+rentersMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
                System.out.println("添加时间:"+rentersMoney.getAddTime());
                System.out.println("订单Id:"+rentersMoney.getOrderInfoId());
                System.out.println("订单编号:"+rentersMoney.getOrderInfoNum());
                System.out.println("流水金额:"+rentersMoney.getMoneyNum());
                System.out.println("出租客信息Id:"+rentersMoney.getRentersInfoId());
                System.out.println("出租客流水Id:"+rentersMoney.getRentersMoneyId());

                // 更新出租客收入统计
                System.out.println("===============2 统计出租客收入与出租小时数=========================");
                addRentersIncome(rentersMoney.getRentersInfoId(),rentersMoney.getMoneyNum());
                addRentersStallHour(rentersMoney.getRentersInfoId(),order.getEnduHour());

            }

            platformMoneyDao.insert(platMoney);
            System.out.println("===============3 添加平台流水=========================");
            System.out.println("添加时间:"+platMoney.getAddTime());
            System.out.println("流水类型:"+platMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
            System.out.println("订单Id:"+platMoney.getOrderInfoId());
            System.out.println("订单编号:"+platMoney.getOrderInfoNum());
            System.out.println("流水金额:"+platMoney.getMoneyNum());
            System.out.println("平台流水Id:"+platMoney.getPlatformMoneyId());


            // 更新平台收入统计
            System.out.println("===============4 统计平台收入与出租小时数=========================");
            addPlatformIncome(platMoney.getMoneyNum());
            addPlatformStallHour(order.getEnduHour());
         }
    }

    /**
     * 取消订单后生成三方收入流水
     * 参数 data 是两个数据的拼接
     *      orderInfoNum      订单编号
     *      isHalf            true表示半价退款 false表示全价退款
     * */
    @RabbitHandler
    @Transactional
    @RabbitListener(queuesToDeclare = {@Queue(value="moneyByDelete")})
    public void moneyByDeleteConsumer(String data) throws Exception {
        System.out.println("======================进入退款消息队列=====================");
        System.out.println("data:"+data);
        Integer moneyType = StateData.ORDER_MONEY_TYPE_DELETE_ORDER;
        String[] datas = data.split(",");
        String orderInfoNum = datas[0];
        boolean isHalf = Boolean.parseBoolean(datas[1]);
        System.out.println("======================进入退款消息队列111111111=====================");
        long poss = platformMoneyDao.selectCount(new QueryWrapper<PlatformMoney>().eq("order_info_num", orderInfoNum).eq("money_type",StateData.ORDER_MONEY_TYPE_DELETE_ORDER));
        System.out.println("======================进入退款消息队列2222222222222=====================");
        System.out.println("========================进入退款消息队列poss:"+poss+"====================");
        if(poss==0){
            System.out.println("===============用户取消订单 退款=========================");

            LocalDateTime now = LocalDateTime.now();
            OrderInfo order = orderInfoDao.selectOne(new QueryWrapper<OrderInfo>().eq("order_info_num",orderInfoNum));
            // 用户取消订单时 若订单开始时间距离现在大于半小时 则退全款 否则退特定比例
            BigDecimal orderPrice = order.getOrderPrice().negate();
            if(isHalf) orderPrice = orderPrice.multiply(StateData.ORDER_REFUND_RATE_PENALTY);

            // 添加平台流水日志
            PlatformMoney platMoney = new PlatformMoney(now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());

            StallDto stall = basicInfoUtil.getStallInfo2(order.getStallInfoId());
            if(stall.getRentersInfoId()==null){
                // 添加物业流水日志
                platMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_RENTERS));
                CentifiedMoney certifiedMoney = new CentifiedMoney(stall.getCertifiedInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                certifiedMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_CERTIFIED));
                centifiedMoneyDao.insert(certifiedMoney);
                System.out.println("===============物业流水日志添加=========================");
                // 更新物业收入统计
                addCertifiedIncome(certifiedMoney.getCertifiedInfoId(), certifiedMoney.getMoneyNum());
                addCertifiedStallHour(certifiedMoney.getCertifiedInfoId(), -order.getEnduHour());
                System.out.println("===============物业收入与小时数添加=========================");
            }

            if(stall.getRentersInfoId()!=null){
                // 添加出租客流水日志
                platMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_CERTIFIED));
                RentersMoney rentersMoney = new RentersMoney(stall.getRentersInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                rentersMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_RENTERS));
                rentersMoneyDao.insert(rentersMoney);
                System.out.println("===============出租客流水日志添加=========================");
                // 更新出租客收入统计
                addRentersIncome(rentersMoney.getRentersInfoId(),rentersMoney.getMoneyNum());
                addRentersStallHour(rentersMoney.getRentersInfoId(),-order.getEnduHour());
                System.out.println("===============出租客收入与小时数添加=========================");
            }

            platformMoneyDao.insert(platMoney);
            System.out.println("===============平台流水日志添加=========================");
            // 更新平台收入统计
            addPlatformIncome(platMoney.getMoneyNum());
            addPlatformStallHour(-order.getEnduHour());
            System.out.println("===============平台收入与小时数添加=========================");


            String refundReason = isHalf?"用户主动申请退款(半额)":"用户主动申请退款(全额)";
            // 开始给用户退款
            System.out.println("开始执行Alipay退款");
            alipayUtil.refund(new AlipayRefundParam(orderInfoNum,refundReason,orderPrice.abs()));
            System.out.println("执行Alipay退款完成");
        }
    }

    /**
     * 取消订单后批量生成三方收入流水
     * 参数 List<Integer>
     *          orderInfoId 订单Id
     * */
    @RabbitHandler
    @Transactional
    @RabbitListener(queuesToDeclare = {@Queue(value="moneyByDeleteList")})
    public void moneyByDeleteListConsumer(String data) throws Exception {
        System.out.println("data:"+data);


        Integer moneyType = StateData.ORDER_MONEY_TYPE_DELETE_ORDER;
        String[] datas = data.split(",");

        List<Integer> orderIds = new ArrayList<>();
        for(int i=0;i<datas.length;i++){
            orderIds.add(Integer.valueOf(datas[i]));
        }

        long poss = platformMoneyDao.selectCount(new QueryWrapper<PlatformMoney>().in("order_info_id", orderIds).eq("money_type",StateData.ORDER_MONEY_TYPE_DELETE_ORDER));
        if(poss==0){
            System.out.println("===============批量取消订单退款=========================");

            LocalDateTime now = LocalDateTime.now();
            List<OrderInfo> orders = orderInfoDao.selectBatchIds(orderIds);
            String refundReason = "租界车位被超时车辆占用 系统自动退单";

            List<PlatformMoney> platformMonies = new ArrayList<>();
            List<RentersMoney> rentersMonies = new ArrayList<>();
            List<CentifiedMoney> certifiedMonies = new ArrayList<>();
            for (OrderInfo order : orders) {
                // 系统自动取消订单时 退全款
                BigDecimal orderPrice = order.getOrderPrice().negate();
                // 添加平台流水日志
                PlatformMoney platMoney = new PlatformMoney(now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());

                StallDto stall = basicInfoUtil.getStallInfo2(order.getStallInfoId());
                if(stall.getRentersInfoId()==null){
                    // 添加物业流水日志
                    platMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_RENTERS));
                    CentifiedMoney certifiedMoney = new CentifiedMoney(stall.getCertifiedInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                    certifiedMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_CERTIFIED));
                    certifiedMonies.add(certifiedMoney);
                    // 更新物业收入统计
                    System.out.println("===============1 批量统计物业收入与出租小时数=========================");
                    addCertifiedIncome(certifiedMoney.getCertifiedInfoId(), certifiedMoney.getMoneyNum());
                    addCertifiedStallHour(certifiedMoney.getCertifiedInfoId(), -order.getEnduHour());
                }

                if(stall.getRentersInfoId()!=null){
                    // 添加出租客流水日志
                    platMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_CERTIFIED));
                    RentersMoney rentersMoney = new RentersMoney(stall.getRentersInfoId(),now,moneyType,order.getOrderInfoId(),order.getOrderInfoNum());
                    rentersMoney.setMoneyNum(orderPrice.multiply(StateData.ORDER_RATE_RENTERS));
                    rentersMonies.add(rentersMoney);
                    // 更新出租客收入统计
                    System.out.println("===============1 批量统计出租客收入与出租小时数=========================");
                    addRentersIncome(rentersMoney.getRentersInfoId(),rentersMoney.getMoneyNum());
                    addRentersStallHour(rentersMoney.getRentersInfoId(),-order.getEnduHour());
                }
                platformMonies.add(platMoney);
                System.out.println("===============2 批量统计平台收入与出租小时数=========================");
                addPlatformIncome(platMoney.getMoneyNum());
                addPlatformStallHour(-order.getEnduHour());
            }
            // 批量添加
            System.out.println("===============3 批量添加平台流水=========================");
            platformMoneyService.saveBatch(platformMonies);
            for (PlatformMoney platformMoney : platformMonies) {
                System.out.println("添加时间:"+platformMoney.getAddTime());
                System.out.println("流水类型:"+platformMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
                System.out.println("订单Id:"+platformMoney.getOrderInfoId());
                System.out.println("订单编号:"+platformMoney.getOrderInfoNum());
                System.out.println("流水金额:"+platformMoney.getMoneyNum());
                System.out.println("平台流水Id:"+platformMoney.getPlatformMoneyId());
            }

            if(!certifiedMonies.isEmpty()) {
                System.out.println("===============4 批量添加物业流水=========================");
                certifiedMoneyService.saveBatch(certifiedMonies);
                for (CentifiedMoney certifiedMoney : certifiedMonies) {
                    System.out.println("添加时间:"+certifiedMoney.getAddTime());
                    System.out.println("流水类型:"+certifiedMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
                    System.out.println("订单Id:"+certifiedMoney.getOrderInfoId());
                    System.out.println("订单编号:"+certifiedMoney.getOrderInfoNum());
                    System.out.println("流水金额:"+certifiedMoney.getMoneyNum());
                    System.out.println("物业信息Id:"+certifiedMoney.getCertifiedInfoId());
                    System.out.println("物业流水Id:"+certifiedMoney.getCertifiedMoneyId());
                }
            }
            if(!rentersMonies.isEmpty()) {
                System.out.println("===============4 批量添加出租客流水=========================");
                rentersMoneyService.saveBatch(rentersMonies);
                for (RentersMoney rentersMoney : rentersMonies) {
                    System.out.println("流水类型:"+rentersMoney.getMoneyType()+"0普通订单 1退款订单 2超时订单");
                    System.out.println("添加时间:"+rentersMoney.getAddTime());
                    System.out.println("订单Id:"+rentersMoney.getOrderInfoId());
                    System.out.println("订单编号:"+rentersMoney.getOrderInfoNum());
                    System.out.println("流水金额:"+rentersMoney.getMoneyNum());
                    System.out.println("出租客信息Id:"+rentersMoney.getRentersInfoId());
                    System.out.println("出租客流水Id:"+rentersMoney.getRentersMoneyId());
                }
            }

            // 开始给用户退款
            System.out.println("===============5 批量订单退款=========================");
            System.out.println("退款理由:"+refundReason);
            for (OrderInfo order : orders) {
                alipayUtil.refund(new AlipayRefundParam(order.getOrderInfoNum(),refundReason,order.getOrderPrice()));
                System.out.println("订单编号:"+order.getOrderInfoNum());
                System.out.println("订单价格=退款价格:"+order.getOrderPrice());
            }
        }
    }

    /**
     * 用户支付超时订单后生成三方流水
     * 参数 orderInfoNum 订单编号
     * */
    @RabbitHandler
    @Transactional
    @RabbitListener(queuesToDeclare = {@Queue(value="moneyOvertime")})
    public void moneyOvertimeConsumer(String orderInfoNum) throws Exception {
        Integer moneyType = StateData.ORDER_MONEY_TYPE_OVERTIME_ORDER;

        long poss = platformMoneyDao.selectCount(new QueryWrapper<PlatformMoney>().eq("order_info_num", orderInfoNum).eq("money_type",StateData.ORDER_MONEY_TYPE_OVERTIME_ORDER));
        if(poss==0){
            LocalDateTime now = LocalDateTime.now();
            OrderOvertime overtime = orderOvertimeDao.selectOne(new QueryWrapper<OrderOvertime>().eq("order_info_num",orderInfoNum));
            BigDecimal payPrice = overtime.getPayPrice();

            // 添加平台流水日志
            PlatformMoney platMoney = new PlatformMoney(now,moneyType,overtime.getOrderInfoId(),overtime.getOrderInfoNum());

            StallDto stall = basicInfoUtil.getStallInfo2(overtime.getStallInfoId());
            if(stall.getRentersInfoId()==null){
                // 添加物业流水日志
                platMoney.setMoneyNum(payPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_RENTERS));
                CentifiedMoney certifiedMoney = new CentifiedMoney(stall.getCertifiedInfoId(),now,moneyType,overtime.getOrderInfoId(),overtime.getOrderInfoNum());
                certifiedMoney.setMoneyNum(payPrice.multiply(StateData.ORDER_RATE_CERTIFIED));
                centifiedMoneyDao.insert(certifiedMoney);
                // 更新物业收入统计
                addCertifiedIncome(certifiedMoney.getCertifiedInfoId(), certifiedMoney.getMoneyNum());
                addCertifiedStallHour(certifiedMoney.getCertifiedInfoId(), overtime.getEnduHour());

            }

            if(stall.getRentersInfoId()!=null){
                // 添加出租客流水日志
                platMoney.setMoneyNum(payPrice.multiply(StateData.ORDER_RATE_PLATFORM_FROM_CERTIFIED));
                RentersMoney rentersMoney = new RentersMoney(stall.getRentersInfoId(),now,moneyType,overtime.getOrderInfoId(),overtime.getOrderInfoNum());
                rentersMoney.setMoneyNum(payPrice.multiply(StateData.ORDER_RATE_RENTERS));
                rentersMoneyDao.insert(rentersMoney);
                // 更新出租客收入统计
                addRentersIncome(rentersMoney.getRentersInfoId(),rentersMoney.getMoneyNum());
                addRentersStallHour(rentersMoney.getRentersInfoId(),overtime.getEnduHour());

            }

            platformMoneyDao.insert(platMoney);
            // 更新平台收入统计
            addPlatformIncome(platMoney.getMoneyNum());
            addPlatformStallHour(overtime.getEnduHour());

        }
    }

    /**
     * 平台添加收入
     * 参数 income 收入
     * */
    public void addPlatformIncome(BigDecimal income){
        System.out.println("平台收入");
        System.out.println("更新前:"+(redisUtil.exist(RedisKey.platformIncome())?redisUtil.get(RedisKey.platformIncome()):0));
        if(redisUtil.exist(RedisKey.platformIncome())){
            redisUtil.set(RedisKey.platformIncome(),(new BigDecimal(redisUtil.get(RedisKey.platformIncome())).add(income)).toString());
        }else redisUtil.set(RedisKey.platformIncome(),income.toString());
        System.out.println("更新后:"+redisUtil.get(RedisKey.platformIncome()));
    }

    /**
     * 平台添加出租小时数
     * 参数 enduHour 出租小时数
     * */
    public void addPlatformStallHour(Integer enduHour){
        System.out.println("平台出租小时数");
        System.out.println("更新前:"+(redisUtil.exist(RedisKey.platformStallHour())?redisUtil.get(RedisKey.platformStallHour()):0));
        if(redisUtil.exist(RedisKey.platformStallHour())){
            redisUtil.set(RedisKey.platformStallHour(), String.valueOf((Integer.parseInt(redisUtil.get(RedisKey.platformStallHour()))+enduHour)));
        }else redisUtil.set(RedisKey.platformStallHour(),String.valueOf(enduHour));
        System.out.println("更新后:"+redisUtil.get(RedisKey.platformStallHour()));
    }

    /**
     * 物业添加收入
     * 参数 certifiedInfoId 物业Id
     *      income          收入
     * */
    public void addCertifiedIncome(Integer certifiedInfoId, BigDecimal income){
        System.out.println("物业收入");
        System.out.println("更新前:"+(redisUtil.isZSetMember(RedisKey.certifiedIncome(),String.valueOf(certifiedInfoId))?redisUtil.ZSetScore(RedisKey.certifiedIncome(), String.valueOf(certifiedInfoId)):0));
        if(redisUtil.isZSetMember(RedisKey.certifiedIncome(),String.valueOf(certifiedInfoId))){
            redisUtil.zadd(RedisKey.certifiedIncome(),String.valueOf(certifiedInfoId),(BigDecimal.valueOf(redisUtil.ZSetScore(RedisKey.certifiedIncome(), String.valueOf(certifiedInfoId))).add(income)).doubleValue());
        }else redisUtil.setZSet(RedisKey.certifiedIncome(),String.valueOf(certifiedInfoId),income.doubleValue());
        System.out.println("更新后:"+redisUtil.ZSetScore(RedisKey.certifiedIncome(), String.valueOf(certifiedInfoId)));
    }

    /**
     * 物业添加出租小时数
     * 参数 certifiedInfoId 物业Id
     *     enduHour         出租小时数
     * */
    public void addCertifiedStallHour(Integer certifiedInfoId, Integer enduHour){
        System.out.println("物业出租小时数");
        System.out.println("更新前:"+(redisUtil.isZSetMember(RedisKey.certifiedStallHour(),String.valueOf(certifiedInfoId))?redisUtil.ZSetScore(RedisKey.certifiedStallHour(), String.valueOf(certifiedInfoId)):0));
        if(redisUtil.isZSetMember(RedisKey.certifiedStallHour(),String.valueOf(certifiedInfoId))){
            redisUtil.zadd(RedisKey.certifiedStallHour(),String.valueOf(certifiedInfoId),redisUtil.ZSetScore(RedisKey.certifiedStallHour(),String.valueOf(certifiedInfoId))+enduHour);
        }else redisUtil.setZSet(RedisKey.certifiedStallHour(),String.valueOf(certifiedInfoId),enduHour);
        System.out.println("更新后:"+redisUtil.ZSetScore(RedisKey.certifiedStallHour(), String.valueOf(certifiedInfoId)));
    }

    /**
     * 出租客添加收入
     * 参数 rentersInfoId 出租客Id
     *     income         收入
     * */
    public void addRentersIncome(Integer rentersInfoId, BigDecimal income){
        System.out.println("出租客收入");
        System.out.println("更新前:"+(redisUtil.isZSetMember(RedisKey.rentersIncome(),String.valueOf(rentersInfoId))?redisUtil.ZSetScore(RedisKey.rentersIncome(),String.valueOf(rentersInfoId)):0));
        if(redisUtil.isZSetMember(RedisKey.rentersIncome(),String.valueOf(rentersInfoId))){
            redisUtil.zadd(RedisKey.rentersIncome(),String.valueOf(rentersInfoId),(BigDecimal.valueOf(redisUtil.ZSetScore(RedisKey.rentersIncome(), String.valueOf(rentersInfoId))).add(income)).doubleValue());
        }else redisUtil.setZSet(RedisKey.rentersIncome(),String.valueOf(rentersInfoId),income.doubleValue());
        System.out.println("更新后:"+redisUtil.ZSetScore(RedisKey.rentersIncome(),String.valueOf(rentersInfoId)));
    }

    /**
     * 出租客添加出租小时数
     * 参数 rentersInfoId 出租客Id
     *     enduHour      出租小时数
     * */
    public void addRentersStallHour(Integer rentersInfoId, Integer enduHour){
        System.out.println("出租客出租小时数");
        System.out.println("更新前:"+(redisUtil.isZSetMember(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId))?redisUtil.ZSetScore(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId)):0));
        if(redisUtil.isZSetMember(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId))){
            redisUtil.zadd(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId),redisUtil.ZSetScore(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId))+enduHour);
        }else redisUtil.setZSet(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId),enduHour);
        System.out.println("更新后:"+redisUtil.ZSetScore(RedisKey.rentersStallHour(),String.valueOf(rentersInfoId)));
    }
}
